package model.semantics.infinary;

import model.RGBColor;
import model.semantics.InfinaryOperation;

/**
 * Find the average of some number of colors.
 * 
 * @author Anne Weng
 */
public class Average extends InfinaryOperation {

	@Override
    protected RGBColor evaluateColor (RGBColor[] colors)
    {
		double sumRed = 0;
		double sumBlue = 0;
		double sumGreen = 0;
		int numArgs = colors.length;
		for (RGBColor current : colors)
		{
			sumRed = sumRed + current.getRed();
			sumBlue = sumBlue + current.getBlue();
			sumGreen = sumGreen + current.getGreen();
		}
		return new RGBColor(sumRed/numArgs, sumBlue/numArgs, sumGreen/numArgs);
    }
	
}
